using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using UnityEngine;

public class VLifeCore : MonoBehaviour
{

    public BoundFloat hunger = new BoundFloat(0, 100);
    public BoundFloat energy = new BoundFloat(0, 100);
    public BoundFloat pressure = new BoundFloat(0, 100);
    public Dictionary<string, string> property; // 应该根据这个写,动态配置
    public Dictionary<string, string> environment;

    public LLM_IPairs_VLifeEnterState interactHandler;
    public string lastPlan;

    public void Save(LLMInteractPairsBase interacts)=>this.Save(interacts);

}
public class VLiftCharacter
{
    public virtual void WriteCharacterInfo(VLifeCore core) { }
    public virtual void WriteEnvironmentInfo(VLifeCore core) { }
}

public class VLifeC_Student : VLiftCharacter
{
    public override void WriteCharacterInfo(VLifeCore core)
    {

        core.property = new Dictionary<string, string>()
        {
            ["role"] = "学生",
            ["name"] = "sake",
            ["hobby"] = "playing pingpong , computergames",
            ["tag"] = "需要履行作为学生的职责, 有暗恋的女孩子, 偶尔会逃课上网 , 因为青春痘导致自卑"
        };
    }
    public override void WriteEnvironmentInfo(VLifeCore core)
    {
        core.environment = new Dictionary<string, string>()
        {
            ["school"] = "XYZ University",
            ["major"] = "Computer Science",
        };
    }
}


public class BoundFloat
{
    private float bot;
    private float top;
    public BoundFloat(float bot, float top)
    {
        this.bot = bot;
        this.top = top;
    }
    public Action<float> onReachTop;
    public Action<float> onReachBottom;
    public Action<float> onValueChange;
    public float Value
    {
        get => _value;
        set
        {
            if (value == 0) return;
            float v = _value + value;
            if (value > 0)
            {
                if (_value == top) return;
                if (v >= top)
                {
                    _value = top;
                    onReachTop?.Invoke(top);
                    return;
                }
            }
            else
            {
                if (_value == bot) return;
                if (v <= bot)
                {
                    _value = bot;
                    onReachBottom?.Invoke(top);
                    return;
                }
            }
            _value = v;
            onValueChange?.Invoke(_value);
        }
    }
    private float _value = 0;

}

